package com.chat.module.act;

import com.chat.comment.core.ResponseResult;
import com.chat.module.act.vo.UserActionVo;
import com.chat.module.user.domain.User;
import com.chat.module.user.service.impl.UserServiceImpl;
import com.comment.util.JwtUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/userAct")
public class UserAction {
    @Resource
    private UserServiceImpl userService;
    @ApiOperation("添加好友")
    @PostMapping("/addFriend")
    public ResponseResult<?> addFriend(
            @RequestHeader String token,
            @RequestBody UserActionVo.addFriend vo
    ) {
        userService.addFriend(JwtUtils.getUserId(token),vo.getUserIds());
        return ResponseResult.success();
    }
    @ApiOperation("同意好友申请")
    @PostMapping("/agreeAddFriend")
    public ResponseResult<User> agreeAddFriend(
            @RequestHeader String token,
            @RequestBody UserActionVo.agreeAddFriend vo
    ) {
        return ResponseResult.success( userService.agreeAddFriend(JwtUtils.getUserId(token),vo.getUserIds()));
    }
    @ApiOperation("拒绝好友申请")
    @PostMapping("/refuseAddFriend")
    public ResponseResult<User> refuseAddFriend(
            @RequestHeader String token,
            @RequestBody UserActionVo.refuseAddFriend vo
    ) {
        return ResponseResult.success( userService.refuseAddFriend(JwtUtils.getUserId(token),vo.getUserIds()));
    }


    @ApiOperation("删除好友")
    @PostMapping("/deleteFriend")
    public ResponseResult<User> deleteFriend(
            @RequestHeader String token,
            @RequestBody UserActionVo.deleteFriend vo
    ) {
        return ResponseResult.success( userService.deleteFriend(JwtUtils.getUserId(token),vo.getUserIds()));
    }

    @ApiOperation("拉黑")
    @PostMapping("/blackout")
    public ResponseResult<User> blackout(
            @RequestHeader String token,
            @RequestBody UserActionVo.blackout vo
    ) {
        return ResponseResult.success( userService.blackout(JwtUtils.getUserId(token),vo.getUserIds()));
    }

    @ApiOperation("解除拉黑")
    @PostMapping("/releaseBlackout")
    public ResponseResult<User> releaseBlackout(
            @RequestHeader String token,
            @RequestBody UserActionVo.releaseBlackout vo
    ) {
        return ResponseResult.success( userService.releaseBlackout(JwtUtils.getUserId(token),vo.getUserIds()));
    }


    @ApiOperation("个人信息")
    @PostMapping("/info")
    public ResponseResult<User> info(
            @RequestHeader String token
    ) {
        return ResponseResult.success(userService.getById(JwtUtils.getPlayerId(token)));
    }
}
